/* Pineapple Blueboard - Assessments script */

$(document).ready(function (){

	$('#butpub').click(function(){
		
		var maxWeight = parseInt($('#weight_max').html());
		var wantWeight = parseInt($('#txtweig').val());
		if($('#txttitle').val().length == 0 ||
		$('#txtdued').val().length == 0 ||
		$('#txtduet').val().length == 0 ||
		$('#txtdesc').val().length == 0 ||
		$('#txtweig').val().length == 0){
		
		$('#warnbox').html('Please Ensure That All Fields Are Filled.');
		$('#warnbox').slideDown(300,'easeOutCubic').delay(2000).fadeTo(300,0.0).slideUp(700,'easeOutBack', function(){
		$(this).css('opacity','1');
		$(this).clearQueue();
		});
		
		} else if( wantWeight > maxWeight){
		
		$('#warnbox').html('Please ensure the set weight is only as large as the maximum shown.');
		$('#txtweig').focus();
		$('#warnbox').slideDown(300,'easeOutCubic').delay(2000).fadeTo(300,0.0).slideUp(700,'easeOutBack', function(){
		$(this).css('opacity','1');
		$(this).clearQueue();
		});
		
		}else if( wantWeight == 0){
		
		$('#warnbox').html('Please do not create an assessment item worth nothing.');
		$('#txtweig').focus();
		$('#warnbox').slideDown(300,'easeOutCubic').delay(2000).fadeTo(300,0.0).slideUp(700,'easeOutBack', function(){
		$(this).css('opacity','1');
		$(this).clearQueue();
		});
		
		}else if( wantWeight < 0){
		
		$('#warnbox').html('Please do not create an assessment item worth negative points.');
		$('#txtweig').focus();
		$('#warnbox').slideDown(300,'easeOutCubic').delay(2000).fadeTo(300,0.0).slideUp(700,'easeOutBack', function(){
		$(this).css('opacity','1');
		$(this).clearQueue();
		});
		
		} else{
		$("#assessment_form").submit();
		}
		return false;
	});
	
	$('#txtdued').datepicker({ dateFormat: "dd/mm/yy" });
	$('#txtduet').timepicker();
	
	
});